#!/bin/bash

# For NVIDIA Jetson Module Camera test
#
# NOTE:
# Support Camera List:
# Sensing: SG2-IMX390C-5200-GMSL2-Hxxx
# Sensing: SG2-AR0233C-5200-GMSL2-Hxxx

# Camera device node
CAM_NODE=/dev/video$1

# Camera output format UYVY
CAM_FORMAT=UYVY

# Camera output resolution
RESOLUTION=1920x1080
WIDTH=$(echo ${RESOLUTION} | cut -dx -f1)
HEIGHT=$(echo ${RESOLUTION} | cut -dx -f2)

########################################################

function usage()
{
	echo -e "Usage: ./$(basename $0) <cam>\n"
	echo -e "  cam can be 0, 1, 2, ... 7"
	echo -e "  eg: ./$(basename $0) 0\n"
}

########################################################

if [[ $# -lt 1 ]]; then
	usage
	exit 1
fi

if [[ ! ${CAM_NODE} =~ ^/dev/video[0-7]$ ]]; then
	usage
	exit 1
fi

#export DISPLAY=:1
gst-launch-1.0 \
    v4l2src device=${CAM_NODE} \
	! video/x-raw,format=${CAM_FORMAT},width=${WIDTH},height=${HEIGHT} \
    ! fpsdisplaysink video-sink=xvimagesink sync=false
